package com.diy.sigmund.diycommon.designpatterns.command;

/**
 * @author ylm-sigmund
 * @since 2022/2/9 10:49
 */
public class RemoteLoader {

    public static void main(String[] args) {
        // 基本款测试
        System.out.println("基本款测试");
        Light light = new Light("Live Room");
        LightOnCommand lightOnCommand = new LightOnCommand(light);
        LightOffCommand lightOffCommand = new LightOffCommand(light);

        RemoteControlWithUndo remoteControlWithUndo = new RemoteControlWithUndo();
        remoteControlWithUndo.setCommand(0, lightOnCommand, lightOffCommand);

        remoteControlWithUndo.onButtonWasPressed(0);
        remoteControlWithUndo.offButtonWasPressed(0);
        remoteControlWithUndo.undoButtonWasPressed();

        remoteControlWithUndo.offButtonWasPressed(0);
        remoteControlWithUndo.onButtonWasPressed(0);
        remoteControlWithUndo.undoButtonWasPressed();

        // 测试吊扇
        System.out.println("测试吊扇");
        CeilingFan ceilingFan = new CeilingFan("Live Room");
        CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);
        CeilingFanLowCommand ceilingFanLowCommand = new CeilingFanLowCommand(ceilingFan);
        CeilingFanHignCommand ceilingFanHignCommand = new CeilingFanHignCommand(ceilingFan);

        remoteControlWithUndo.setCommand(1, ceilingFanLowCommand, ceilingFanOffCommand);
        remoteControlWithUndo.setCommand(2, ceilingFanHignCommand, ceilingFanOffCommand);

        remoteControlWithUndo.onButtonWasPressed(1);
        remoteControlWithUndo.onButtonWasPressed(2);
        remoteControlWithUndo.undoButtonWasPressed();

        remoteControlWithUndo.offButtonWasPressed(1);
        remoteControlWithUndo.onButtonWasPressed(1);
        remoteControlWithUndo.offButtonWasPressed(2);
        remoteControlWithUndo.onButtonWasPressed(2);
        remoteControlWithUndo.undoButtonWasPressed();

        // 测试宏命令
        System.out.println("测试宏命令");
        Command[] commands = {lightOnCommand, ceilingFanLowCommand, ceilingFanHignCommand};
        Command[] undoCommands = {lightOffCommand, ceilingFanOffCommand};
        MacroCommand macroCommand = new MacroCommand(commands);
        MacroCommand undoMacroCommand = new MacroCommand(undoCommands);
        remoteControlWithUndo.setCommand(3, macroCommand, undoMacroCommand);

        remoteControlWithUndo.onButtonWasPressed(3);
        remoteControlWithUndo.offButtonWasPressed(3);
        remoteControlWithUndo.undoButtonWasPressed();

    }

}
